const mongoose = require('mongoose');
const db = mongoose.connection;

module.exports = () => {

  return new Promise((resolve, reject) => {

    db.on('error', () => {
      reject();
      console.log.bind(console, 'mongodb connection error');
    }).on('open', () => {
      resolve();
      console.log('mongodb connected');
    });

    mongoose.connect('mongodb://localhost:27017/db_wecahat', { useNewUrlParser: true });
  });
}